package com.styytech.dadabao.api.templates;

import android.content.Context;
import android.util.Log;

import com.loopj.android.http.RequestParams;
import com.styytech.dadabao.api.operations.AbstractOperations;
import com.styytech.dadabao.api.operations.ProductOperations;
import com.styytech.dadabao.api.requestresult.RequestResult;
import com.styytech.dadabao.api.response.ClientRequestUtil;
import com.styytech.dadabao.exception.RequestException;
import com.styytech.dadabao.utils.SpUser;
import com.styytech.dadabao.exception.ArgumentsException;

public class HttpRequest extends AbstractOperations implements
		ProductOperations {

	public HttpRequest(Context paramContext) {
		super(paramContext);
	}

	@Override
	public void setToken(RequestParams params) {
		String token =getToke() ;
		Log.i("INFO", "token:" + token);
		if(token!=null){
			params.put("token", getToke());
		}
	}

	@Override
	public String getToke() {
		String token = SpUser.getUserToken(getContext());
		return token;
	}

	/**
	 * post请求
	 */
	@Override
	public void doPost(RequestResult result,String url, RequestParams params ) throws RequestException, ArgumentsException {
		setToken(params);
		ClientRequestUtil util = new ClientRequestUtil(result);
		util.doPost(url, params);
	}
	/**
	 *get请求
	 */
	@Override
	public void doGet(RequestResult result,String url ) throws RequestException, ArgumentsException {
		ClientRequestUtil util = new ClientRequestUtil(result);
		util.doGet(url);
	}

}